package cn.rokhdelar.ams.management.controller;

import cn.rokhdelar.ams.management.domain.query.LoginQuery;
import cn.rokhdelar.ams.management.service.AuthenticationService;
import cn.rokhdelar.ams.management.service.CaptchaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/auth")
@Schema(title = "用户认证接口", description = "用户认证接口")
@Tag(name = "用户认证接口")
@RequiredArgsConstructor
public class AuthenticationController {
    private final AuthenticationService authenticationService;
    private final CaptchaService captchaService;
//
//    @GetMapping(value = "/kaptcha")
//    public ResponseEntity<Map<String, String>> getCaptcha() {
//        return ResponseEntity.ok(captchaService.getCaptcha());
//    }

    @PostMapping(value = "/login")
    @Operation(summary = "用户登录")
    public Map<String, Object> login(@RequestBody LoginQuery longinQuery, HttpServletRequest request) {
        return authenticationService.login(longinQuery, request);
    }

    @PostMapping(value = "/verify")
    public ResponseEntity<Boolean> verifyToken(@RequestBody Map<String, String> map) {
        String token = map.get("token");
        return ResponseEntity.ok(authenticationService.verifyToken(token));
    }

}
